package cn.kgc.appinfo.common.utils;

public class Pager {
    private int pageIndex = 1;                //当前页页码
    private int pageSize = 8;             //每页多少行
    private int totalRow;                 //总行数
    private int totalPage;                //总页数
    private int startIndex;

    public int getPageIndex() {


        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;

    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRow() {
        return totalRow;
    }

    public void setTotalRow(int totalRow) {
        this.totalRow = totalRow;
        //如果总记录数除以每页行数能整除，总页数就是两者相除，否则+1
        this.totalPage = (totalRow % pageSize == 0)?(totalRow / pageSize):(totalRow / pageSize)+1;

        if (pageIndex < 1 ){
            pageIndex = 1;
        }else if (pageIndex > totalPage){
            pageIndex = totalPage;
        }
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;

    }

    public int getStartIndex(){
        this.startIndex = (this.pageIndex-1) * this.pageSize;
        return startIndex;
    }

    @Override
    public String toString() {
        return "Pager{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalRow=" + totalRow +
                ", totalPage=" + totalPage +
                ", StartIndex=" + startIndex +
                '}';
    }
}
